package net.lab1024.sa.admin.module.business.attendance.task.service;

import java.util.List;

import net.lab1024.sa.admin.module.business.attendance.task.dao.AttendanceTaskDao;
import net.lab1024.sa.admin.module.business.attendance.task.domain.entity.AttendanceTaskEntity;
import net.lab1024.sa.admin.module.business.attendance.task.domain.form.AttendanceTaskAddForm;
import net.lab1024.sa.admin.module.business.attendance.task.domain.form.AttendanceTaskQueryForm;
import net.lab1024.sa.admin.module.business.attendance.task.domain.form.AttendanceTaskUpdateForm;
import net.lab1024.sa.admin.module.business.attendance.task.domain.vo.AttendanceTaskVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 考勤任务 Service
 *
 * @Author ZouYang
 * @Date 2024-12-28 12:10:44
 * @Copyright ZouYang
 */

@Service
public class AttendanceTaskService {

    @Resource
    private AttendanceTaskDao attendanceTaskDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<AttendanceTaskVO> queryPage(AttendanceTaskQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<AttendanceTaskVO> list = attendanceTaskDao.queryPage(page, queryForm);
        PageResult<AttendanceTaskVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(AttendanceTaskAddForm addForm) {
        AttendanceTaskEntity attendanceTaskEntity = SmartBeanUtil.copy(addForm, AttendanceTaskEntity.class);
        attendanceTaskDao.insert(attendanceTaskEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(AttendanceTaskUpdateForm updateForm) {
        AttendanceTaskEntity attendanceTaskEntity = SmartBeanUtil.copy(updateForm, AttendanceTaskEntity.class);
        attendanceTaskDao.updateById(attendanceTaskEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        attendanceTaskDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        attendanceTaskDao.updateDeleted(id, true);
        return ResponseDTO.ok();
    }
}
